package com.lllmark.lllmarkDemo.component;

import com.lllmark.lllmarkDemo.constans.Constans;
import com.lllmark.lllmarkDemo.entity.vo.UserVO;
import com.lllmark.lllmarkDemo.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author yuxiangZhang
 * @data 2024/5/12
 */
@Component
@Slf4j
public class RedisComponent {

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private UserMapper userMapper;

    /**
     * 按id查询
     * @param id
     * @return
     */
    public UserVO getUserById(String id){
        UserVO userVO = (UserVO) redisUtils.get(id);
        log.info("用户信息", userVO);
        if (userVO == null){
            userVO = userMapper.selectById(Integer.valueOf(id));
            redisUtils.setex(Constans.REDIS_KEY_USER_INFO + id, userVO, Constans.REDIS_KEY_EXPIRES_30_MIN);
        }
        return userVO;
    }



}
